package com.neusoft.neu24g1.his.controller;

import com.neusoft.neu24g1.his.HisApplication;
import com.neusoft.neu24g1.his.common.ViewInfo;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.stage.Screen;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;

/**
 * HisWinController 整个系统的核心窗口切换核心控制器
 *
 * @author Administrator
 * @version 2024/05/24 08:23
 **/
public class HisWinController {
    private static Stage mainStage;


    public static void setMainStage(Stage stage) {
        mainStage = stage;
    }



    public static void   showView(ViewInfo viewInfo) throws IOException {
        FXMLLoader loader = new FXMLLoader(HisApplication.class.getResource(viewInfo.getUrl()));
        Scene scene = new Scene(loader.load(), viewInfo.getWidth(), viewInfo.getHeight());

        mainStage.setTitle(viewInfo.getTitle());
        mainStage.setScene(scene);

//        调整窗口位置

        Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
        mainStage.setX((screenBounds.getWidth() - viewInfo.getWidth()) / 2);
        mainStage.setY((screenBounds.getHeight() - viewInfo.getHeight()) / 2);
    }

}